package org.example.www;

import java.rmi.RemoteException;

import org.apache.axis2.AxisFault;
import org.example.www.FacadeInterfaceServiceStub;
import org.example.www.FacadeInterfaceServiceStub.GetRestaurantInfoByNameResponse;

import org.example.www.FacadeInterfaceServiceStub.EventsFacadeList;
import org.example.www.FacadeInterfaceServiceStub.GetEventsByDate;
import org.example.www.FacadeInterfaceServiceStub.GetEventsByDateResponse;
import org.example.www.FacadeInterfaceServiceStub.GetEventsByKeyword;
import org.example.www.FacadeInterfaceServiceStub.GetEventsByKeywordResponse;
import org.example.www.FacadeInterfaceServiceStub.GetFacadeGlobalData;
import org.example.www.FacadeInterfaceServiceStub.GetFacadeGlobalDataResponse;
import org.example.www.FacadeInterfaceServiceStub.GetMovieInfoByGenre;
import org.example.www.FacadeInterfaceServiceStub.GetMovieInfoByGenreResponse;
import org.example.www.FacadeInterfaceServiceStub.GetMovieInfoByName;
import org.example.www.FacadeInterfaceServiceStub.GetMovieInfoByNameResponse;
import org.example.www.FacadeInterfaceServiceStub.GetMovieInfoByTheatre;
import org.example.www.FacadeInterfaceServiceStub.GetMovieInfoByTheatreResponse;
import org.example.www.FacadeInterfaceServiceStub.GetMovieInfoByTime;
import org.example.www.FacadeInterfaceServiceStub.GetMovieInfoByTimeResponse;
import org.example.www.FacadeInterfaceServiceStub.GetMovieInfoByType;
import org.example.www.FacadeInterfaceServiceStub.GetMovieInfoByTypeResponse;
import org.example.www.FacadeInterfaceServiceStub.GetNewsByCategory;
import org.example.www.FacadeInterfaceServiceStub.GetNewsByCategoryResponse;
import org.example.www.FacadeInterfaceServiceStub.GetNewsByKeyword;
import org.example.www.FacadeInterfaceServiceStub.GetNewsByKeywordFault;
import org.example.www.FacadeInterfaceServiceStub.GetNewsByKeywordResponse;
import org.example.www.FacadeInterfaceServiceStub.GetRestaurantInfo1ByRating;
import org.example.www.FacadeInterfaceServiceStub.GetRestaurantInfo1ByRatingResponse;
import org.example.www.FacadeInterfaceServiceStub.GetRestaurantInfoByCusine;
import org.example.www.FacadeInterfaceServiceStub.GetRestaurantInfoByCusineResponse;
import org.example.www.FacadeInterfaceServiceStub.GetRestaurantInfoByName;
import org.example.www.FacadeInterfaceServiceStub.GlobalFacadeData;
import org.example.www.FacadeInterfaceServiceStub.MoviesFacade;
import org.example.www.FacadeInterfaceServiceStub.MoviesFacadeList;
import org.example.www.FacadeInterfaceServiceStub.NewsFacadeList;
import org.example.www.FacadeInterfaceServiceStub.RestaurantFacade;
import org.example.www.FacadeInterfaceServiceStub.RestaurantFacadeList;

public class FacadeWSClient
{
	private static final String SERVICE_END_POINT = "http://localhost:8080/axis2/services/FacadeInterfaceService";	
	private FacadeInterfaceServiceStub stub;
	
	public FacadeWSClient()
	{
		try
		{
			stub = new FacadeInterfaceServiceStub(SERVICE_END_POINT);
		} catch (AxisFault e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public EventsFacadeList getEventsByKeyword(String keyword) throws GetEventsByKeywordFaultException, RemoteException
	{
	
		GetEventsByKeywordResponse response = new GetEventsByKeywordResponse();
		GetEventsByKeyword data = new GetEventsByKeyword();
		
		if(keyword == null)
			keyword = "";
		data.setIn(keyword);
		
		try
		{
			response = stub.getEventsByKeyword(data);
		}
		catch(RemoteException e)
		{
			throw e;
		}
		catch(GetEventsByKeywordFaultException ex)
		{
			throw ex;
		}
		return response.getOut();
		
	}
	
	public EventsFacadeList getEventsByDate(String start, String end) throws GetEventsByDateFaultException, RemoteException
	{
		GetEventsByDateResponse response = new GetEventsByDateResponse();
		GetEventsByDate data = new GetEventsByDate();
		
		data.setStart(start);
		data.setEnd(end);
		
		try
		{
			response = stub.getEventsByDate(data);
		}
		catch(RemoteException e)
		{
			throw e;
		}
		catch(GetEventsByDateFaultException ex)
		{
			throw ex;
		}
		return response.getOut();
	}
	
	public RestaurantFacade getRestaurantInfoByName(String name) throws GetRestaurantInfoByNameFaultException
	{
			GetRestaurantInfoByName res = new GetRestaurantInfoByName();
			res.setIn(name);
			GetRestaurantInfoByNameResponse result = new GetRestaurantInfoByNameResponse();

			try
			{
				result = stub.getRestaurantInfoByName(res);
			}
			catch(RemoteException e)
			{
				System.out.println(e.getMessage());
			}
			catch(GetRestaurantInfoByNameFaultException ex)
			{
				throw ex;
			}
			return result.getOut();
	}
	
	public RestaurantFacadeList getRestaurantInfoByCuisine(String cusine) throws GetRestaurantInfoByCusineFaultException
	{
			GetRestaurantInfoByCusine res = new GetRestaurantInfoByCusine();
			res.setIn(cusine);
			GetRestaurantInfoByCusineResponse result = new GetRestaurantInfoByCusineResponse();

			try
			{
				result = stub.getRestaurantInfoByCusine(res);
			}
			catch(RemoteException e)
			{
				System.out.println(e.getMessage());
			}
			catch(GetRestaurantInfoByCusineFaultException ex)
			{
				throw ex;
			}
			return result.getOut();
	}

	public RestaurantFacadeList getRestaurantInfoByRating(double rating) throws GetRestaurantInfo1ByRatingFaultException
	{
		
			GetRestaurantInfo1ByRating res = new GetRestaurantInfo1ByRating();
			res.setIn(rating);
			GetRestaurantInfo1ByRatingResponse result = new GetRestaurantInfo1ByRatingResponse();

			try
			{
				result = stub.getRestaurantInfo1ByRating(res);
			}
			catch(RemoteException e)
			{
				System.out.println(e.getMessage());
			}
			catch(GetRestaurantInfo1ByRatingFaultException ex)
			{
				throw ex;
			}
			
			return result.getOut();
	}
	
	public MoviesFacade getMovieInfoByName(String name) throws GetMovieInfoByNameFaultException, RemoteException
	{
		GetMovieInfoByName param = new GetMovieInfoByName();
		param.setIn(name);
		GetMovieInfoByNameResponse response = new GetMovieInfoByNameResponse();
		try
		{
			response = stub.getMovieInfoByName(param);
		}
		catch(RemoteException e)
		{
			throw e;
		}
		catch(GetMovieInfoByNameFaultException ex)
		{
			throw ex;
		}
		return response.getOut();
	}
	
	public MoviesFacadeList getMovieInfoByGenre(String genre) throws RemoteException, GetMovieInfoByGenreFaultException
	{
		GetMovieInfoByGenre getMovieInfoByGenre = new GetMovieInfoByGenre();
		getMovieInfoByGenre.setIn(genre);
		GetMovieInfoByGenreResponse response = new GetMovieInfoByGenreResponse();
		response = stub.getMovieInfoByGenre(getMovieInfoByGenre);
		return response.getOut();
	}
	public MoviesFacadeList getMovieInfoByTheatre(String theatre) throws RemoteException, GetMovieInfoByTheatreFaultException
	{
		GetMovieInfoByTheatre param = new GetMovieInfoByTheatre();
		param.setIn(theatre);
		GetMovieInfoByTheatreResponse response = new GetMovieInfoByTheatreResponse();
		response = stub.getMovieInfoByTheatre(param);
		return response.getOut();
	}
	
	public MoviesFacadeList getMovieInfoByTime(String time) throws RemoteException, GetMovieInfoByTimeFaultException
	{
		GetMovieInfoByTime param = new GetMovieInfoByTime();
		param.setIn(time);
		GetMovieInfoByTimeResponse response = new GetMovieInfoByTimeResponse();
		response = stub.getMovieInfoByTime(param);
		return response.getOut();
	}
	
	public MoviesFacadeList getMovieInfoByRating(String rating) throws RemoteException, GetMovieInfoByTypeFaultException
	{
		GetMovieInfoByType param = new GetMovieInfoByType();
		param.setIn(rating);
		GetMovieInfoByTypeResponse response = new GetMovieInfoByTypeResponse();
		response = stub.getMovieInfoByType(param);
		return response.getOut();
	}
	
	public GlobalFacadeData getAllGlobalData() throws RemoteException, GetFacadeGlobalDataFaultException
	{
		GetFacadeGlobalData param = new GetFacadeGlobalData();
		param.setIn("");
		GetFacadeGlobalDataResponse response = new GetFacadeGlobalDataResponse();
		response = stub.getFacadeGlobalData(param);
		return response.getOut();
	}
	public NewsFacadeList getNewsByCategory(String category) throws RemoteException, GetNewsByCategoryFaultException
	{
		GetNewsByCategory param = new GetNewsByCategory();
		param.setIn(category);
	
		GetNewsByCategoryResponse response = new GetNewsByCategoryResponse();
		response = stub.getNewsByCategory(param);
		
		return response.getOut();
	}
	
	public NewsFacadeList getNewsByKeyword(String keyword) throws RemoteException, GetNewsByKeywordFaultException
	{
		if(keyword == null)
		{
			GetNewsByKeywordFaultException ex = new GetNewsByKeywordFaultException("Please Enter value in required* fields!");
			throw ex;
		}
		GetNewsByKeyword param = new GetNewsByKeyword();
		param.setIn(keyword);
		
		
		GetNewsByKeywordResponse response = new GetNewsByKeywordResponse();
		
		response = stub.getNewsByKeyword(param);
		return response.getOut();
	}
}
